/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.
*
*/

#ifndef APPMSG_H
#define APPMSG_H

#include <QObject>
#include <QWidget>
#include <QLabel>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QSpacerItem>
#include <QPushButton>
#include <QToolButton>
#include <QDateTime>
#include "notificationPlugin.h"
#include "singlemsg.h"
#include "../commondata.h"
#include "../gsettingmanager.h"

class NotificationPlugin;
class SingleMsg;
class FoldBtn;
class DelBtn;

class AppMsg : public QWidget
{
    Q_OBJECT
public:
    AppMsg(NotificationPlugin *parent, QString strAppName);

    void    addSingleMsg(QString strIconPath, QString strSummary, QDateTime dateTime, QString strBody, QString strUrl, QString strAction); //新增单条消息至通知列表
    void    deleteExceedingMsg();                                    //删除超出最大数的消息
    void    updateAppPushTime();                                     //更新应用最新的推送时间
    int     getSingleMsgCount();                                     //获取应用消息数

    uint    getAppPushTime() {return m_uNotifyTime;}                 //获取消息时间
    QString getAppName() {return m_strAppName;}                      //获取消息名称
    void    setAppFold();                                            //当app展开时，将app设置折叠

    void    setMaxNumMsg(int nMaxNum);                               //设置最大消息通知数
    bool    getFoldFlag() {return m_bFold;}                          //获取折叠状态
    void    setFoldFlag(bool bFlag) {m_bFold = bFlag;}               //设置折叠状态

private:
    void    initUI();                                                //界面初始化
    void    initMaxCount();                                          //初始化最大消息数量
    void    statisticLeftItem();                                     //统计应用剩余显示条数
    void    setTopWithSecondItem();                                  //当应用最顶条被删除后,将第二条置顶
    void    initGsetting();                                          //初始化gsetting
    void    paintEvent(QPaintEvent *);                               //重绘事件

    QVBoxLayout*        m_pMainBaseVLaout;              //APP信息中的整体布局
    QWidget*            m_pMainWid;                     //App信息中的总窗口
    QVBoxLayout*        m_pMainVLaout;                  //App信息中的总的垂直布局器
    QVBoxLayout*        m_pIndexFromOneVLaout;          //1号消息布局
    QWidget*            m_pAppBaseMapWidget;            //多条消息时，底图部件包括底部6个px的空白
    QWidget*            m_pFoldBtnWid;                  //折叠按钮和删除按钮窗口
    FoldBtn*            m_foldBtn;                      //折叠按钮
    DelBtn*             m_delBtn;                       //删除按钮
    QList<SingleMsg*>   m_listSingleMsg;                //对于SingleMsg类对象用list表记录
    QString             m_strAppName;                   //保存发送方的应用名
    QDateTime           m_dateTime;                     //保存推送时间
    uint                m_uNotifyTime;                  //保存推送时间的绝对时间
    bool                m_bFold = true;                 //折叠标志,默认折叠
    int                 m_nMaxCount;                    //应用消息最大收录数,默认20条
    QString             m_pStyleName;                   //保存主题名称

signals:
    void                Sig_onDeleteAppMsg(AppMsg* p);              //该对象属于通知应用,发出删除应用的信号
    void                Sig_foldAnimationFinish();                  //折叠按钮窗口的消失动画完成信号

public slots:
    void                onDeleteAppMsg();                           //删除一个应用消息
    void                onDeleSingleMsg(SingleMsg* pSingleMsg);     //删除单条消息
    void                setAppFoldFlag(bool bFlag);                 //设置应用折叠标志
    void                onShowBaseMap();                            //显示应用底图
    void                onHideBaseMap();                            //隐藏底图部件
    void                onFoldAppWidget();                          //折叠整个应用消息
    void                onDelAppMsg();                              //删除整个应用的消息
    void                onUpdateStyleName();

};

class FoldBtn : public QPushButton
{
    Q_OBJECT
public:
    FoldBtn(QWidget *parent = nullptr);

private:
    PictureToWhite *m_pPictureToWhite;

    void setButtonIcon();
    void paintEvent(QPaintEvent *e);                               //重绘事件


public slots:
    void changeStyle();

};

class DelBtn : public QPushButton
{
    Q_OBJECT
public:
    DelBtn(QWidget *parent = nullptr);

private:
    PictureToWhite *m_pPictureToWhite;

    void setButtonIcon();
    void paintEvent(QPaintEvent *e);                               //重绘事件

public slots:
    void changeStyle();

};

#endif // APPMSG_H
